
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { request } from '@/service/request'

/**
 * Health Store
 * 管理健康数据的状态和操作
 */
export const useHealthStore = defineStore('health', () => {
  const showAdd = ref(false)
  const recordid = ref('')

  
  // 显示添加数据弹出框
  const openAddDialog = () => {
    showAdd.value = true
  }
  
  // 关闭添加数据弹出框
  const closeAddDialog = () => {
    showAdd.value = false
  }
  
  // 切换添加数据弹出框状态
  const toggleAddDialog = () => {
    showAdd.value = !showAdd.value
  }

  const getHealthId = async () => {
    const res: any = await request.get('/health_records/HealthRecord/healthRecordInfo/getNextHealthSequence', {
      sequenceName: "healthSequence",
    }, {
      useErrMsg: true
    })

    recordid.value = res.success.id
  }

  const getHealthRecord = async () => {
    const res: any = await request.get('/health_records/health_basepro/healthBaseProjectInfo/list', {
      recordid: recordid.value,
    },{
      useErrMsg: true
    })
  }

  return {
    recordid,
    getHealthId,
    getHealthRecord,
    showAdd,
    openAddDialog,
    closeAddDialog,
    toggleAddDialog,
  }
}) 